class Solution {
public:
    void duplicateZeros(vector<int>& arr) {
        int cur =0,dest = 0;
        while(dest < arr.size())
        {
            if(arr[cur] == 0)
            {     
                dest++;
                if(dest == arr.size())
                {                    
                    arr[--dest] = 0;
                    cur--;                
                    dest--;                                                  
                    break;
                }             
            }
            dest++;
            cur++;
        }

        if(dest == arr.size())
        {
            dest--;
            cur--;
        }

        while(dest >= 0)
        {
            arr[dest] = arr[cur];
            if(arr[cur] == 0)
            {                                                       
                arr[--dest] = 0;               
            }
            cur--;
            dest--;
        }
    }
};
